import 'package:cached_network_image/cached_network_image.dart';
import 'package:flutter/material.dart';
import 'package:qunaimedical/models/health_news.dart';
import 'package:qunaimedical/pages/news/news_detail.dart';
import 'package:qunaimedical/utils/event_bus_manager.dart';
import 'package:qunaimedical/values/urls.dart';

class ItemHealthNews extends StatelessWidget {
  final HealthNews item;

  const ItemHealthNews({Key key, @required this.item}) : super(key: key);

  @override
  Widget build(BuildContext context) {
    return InkWell(
      onTap: () => Navigator.push(context,
              MaterialPageRoute(builder: (c) => NewsDetailPage(item: item)))
          .then((value) {
        eventBus.fire(EventBusManager(EventBusManager.favoriteRefresh));
      }),
      child: Container(
        height: 120,
        padding: EdgeInsets.symmetric(horizontal: 16, vertical: 16),
        child: Row(
          children: [
            Container(
              margin: EdgeInsets.only(right: 10),
              child: ClipRRect(
                borderRadius: BorderRadius.circular(6),
                child: CachedNetworkImage(
                  imageUrl: '${Urls.BASE_URL}${item.mainImage}',
                  width: 110,
                  height: 90,
                  fit: BoxFit.cover,
                  errorWidget: (c, url, error) => Container(
                    color: Colors.grey[200],
                    width: 110,
                    height: 90,
                  ),
                  placeholder: (c, url) => Container(
                    color: Colors.grey[200],
                    width: 110,
                    height: 90,
                  ),
                ),
              ),
            ),
            Expanded(
              child: Column(
                crossAxisAlignment: CrossAxisAlignment.stretch,
                children: [
                  Expanded(
                    child: Text(
                      item.infoTitle,
                      style:
                          TextStyle(fontSize: 16, fontWeight: FontWeight.bold),
                      maxLines: 3,
                      overflow: TextOverflow.ellipsis,
                    ),
                  ),
                  Row(
                    mainAxisAlignment: MainAxisAlignment.spaceBetween,
                    children: [
                      Text(
                        '${item.viewCount}人阅读',
                        style: Theme.of(context).textTheme.caption,
                      ),
                      Text(
                        item.createDate,
                        style: Theme.of(context).textTheme.caption,
                      ),
                    ],
                  ),
                ],
              ),
            ),
          ],
        ),
      ),
    );
  }
}
